package com.huan.mr2;



import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class FruitDriver2 implements Tool {
    //定义一个 configuration
    private Configuration conf = null;


    @Override
    public int run(String[] args) throws Exception {

        //1.获取job对象
        Job job = Job.getInstance( conf );

        //2.设置驱动类路径
        job.setJarByClass( FruitDriver2.class);

        //3.设置Mapper&Mapper输出的 K V类型
        TableMapReduceUtil.initTableMapperJob( "fruit1" ,
                new Scan(),
                FruitMapper2.class ,
                ImmutableBytesWritable.class,
                Put.class,
                job);

        //4.设置Reducer类
        TableMapReduceUtil.initTableReducerJob( "fruit2", FruitReduce2.class,job );

        //5.提交任务
        boolean result = job.waitForCompletion( true );


        return result ? 0 : 1;
    }

    @Override
    public void setConf(Configuration conf) {
        this.conf = conf;
    }

    @Override
    public Configuration getConf() {
        return conf;
    }

    public static void main(String[] args) {
        try {
           // Configuration conf = new Configuration();
            Configuration conf = HBaseConfiguration.create();
            int run = ToolRunner.run( conf, new FruitDriver2(), args );
            System.exit( run );

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
